﻿using System;
using Aquarinum.WebSocekt.ClientSdk.NET35.Dtos;
using Aquarinum.WebSocekt.ClientSdk.NET35.EventArgs;
using SuperSocket.ClientEngine;
using WebSocket4Net;

namespace Aquarinum.WebSocekt.ClientSdk.NET35.Interfaces
{
    public interface IWebsocketClient : IDisposable
    {
        /// <summary>
        ///     服务器域名
        /// </summary>
        string Host { get; }

        /// <summary>
        ///     用户名
        /// </summary>
        string User { get; }

        /// <summary>
        ///     资源（手机，平板，PC？）
        /// </summary>
        string Resource { get; }

        /// <summary>
        ///     客户端ID
        /// </summary>
        string Clientid { get; }

        /// <summary>
        ///     当前状态
        /// </summary>
        WebSocketState WebSocketState { get; }


        /// <summary>
        ///     使用URL 初始化客户端
        /// </summary>
        /// <param name="user"></param>
        /// <param name="resource"></param>
        /// <param name="host"></param>
        /// <param name="requestTimeout"></param>
        void InitClient(string user, string resource, string host,int requestTimeout=30);

        /// <summary>
        ///     连接服务器
        /// </summary>
        void ConnectServer();

        /// <summary>
        ///     发送消息
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="messageType">消息类型</param>
        /// <param name="messageTo">接收端信息</param>
        ApiResult SendMessage<T>(T message, string messageType, string messageTo)
            where T : class;

        /// <summary>
        ///     发送消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        /// <param name="messageTo"></param>
        /// <returns></returns>
        ApiResult SendMessage<T>(T message, string messageTo) where T : class;

        /// <summary>
        ///     发送
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        ApiResult SendMessage(WebsocketMessageDto message);

        /// <summary>
        ///     关闭
        /// </summary>
        void Close();

        /// <summary>
        ///     关闭
        /// </summary>
        /// <param name="reason"></param>
        void Close(string reason);

        #region Event

        event EventHandler OnClientClosed;
        event EventHandler OnClientOpened;
        event EventHandler<ErrorEventArgs> OnError;
        event EventHandler<WebSoketMessageReciveArgs> OnMessageReceipt;
        event EventHandler<WebSoketMessageReciveArgs> OnClientConnected;
        event EventHandler<WebSoketMessageReciveArgs> OnClientUnAuth;
        event EventHandler<WebSoketMessageReciveArgs> OnRecivedMessage;

        #endregion
    }
}